﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace SimpleDelphiExpert
{
    class TfsFileHistory: FileHistory
    {
        private IList<Changeset> history;
        private IList<Change> changeItem;

        public TfsFileHistory(IEnumerable<Changeset> history)
        {
            this.history = new List<Changeset>();
            this.changeItem = new List<Change>();

            foreach (Changeset cs in history)
            {
                this.history.Add(cs);
                this.changeItem.Add(cs.Changes[0]);
            }
        }

        public override int Count
        {
            get { return this.history.Count; }
        }

        public override string GetAuthor(int index)
        {
            return this.history[index].Committer;
        }

        public override string GetComment(int index)
        {
            return this.history[index].Comment;
        }

        protected override System.IO.Stream DoGetContent(int index)
        {
            return this.changeItem[index].Item.DownloadFile();
        }

        public override DateTime GetDate(int index)
        {
            return this.history[index].CreationDate;
        }

        public override Borland.Studio.ToolsAPI.TOTAHistoryStyle GetHistoryStyle(int index)
        {
            return Borland.Studio.ToolsAPI.TOTAHistoryStyle.hsRemoteRevision;
        }

        public override string GetIdent(int index)
        {
            return String.Format("ChangeSet {0}", this.history[index].ChangesetId);
        }

        public override int GetLabelCount(int index)
        {
            return 1;
        }

        public override string GetLabels(int index, int labelIndex)
        {
            return this.changeItem[index].Item.ItemType.ToString();
        }
    }
}
